﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jungle.Rent;
using Jungle.Code.Core;
using Jungle.Code.Utils;


public partial class AddEditOffer : System.Web.UI.UserControl
{
    SessionKeeper sk = new SessionKeeper();
    //------------------------------------------------------------------------------------------------------
    protected override void OnInit(EventArgs e)
    {
        LoadDdls();

        base.OnInit(e);
    }
    //------------------------------------------------------------------------------------------------------
    private void LoadDdls()
    {
        foreach (ListItem l in Offer.ddl_ObjectType().Items) ddl_ObjectType.Items.Add(l);
        foreach (ListItem l in Offer.ddl_Countrys().Items) ddl_Countrys.Items.Add(l);
    }
    //------------------------------------------------------------------------------------------------------
    public void AddObject(object sender, EventArgs e)
    {
        //try
        //{
            Offer o = new Offer();
            o.ObjectTypeId = Convert.ToInt32(ddl_ObjectType.SelectedValue);
            o.CountryId = Convert.ToInt32(ddl_Countrys.SelectedValue);
            o.City = tb_City.Text.Trim();
            o.Adress = tb_Adress.Text.Trim();
            o.Description = tb_Description.Text.Trim();
            try { o.GroundTax = Convert.ToDouble(tb_GroundTax.Text.Trim()); }
            catch { }
            try { o.Price = Convert.ToDouble(tb_Price.Text.Trim()); }
            catch { }
            try { o.Tax = Convert.ToInt32(tb_Tax.Text.Trim()); }
            catch { }
            try { o.TaxPeriod = Convert.ToInt32(ddl_TaxPeriod.SelectedValue); }
            catch { }
            try { o.Floor = Convert.ToInt32(td_Floor.Text.Trim()); }
            catch { }
            try { o.Floors = Convert.ToInt32(td_Floors.Text.Trim()); }
            catch { }

            ImgUpload1.Upload();
            if (ImgUpload1.preImage.Length > 0)
            {
                o.Photos = ImgUpload1.preImage;
                foreach (string s in ImgUpload1.files)
                {
                    if (s != null) if (s != "ERROR") o.Photos += "," + s;
                }
            }

            try { o.SquareTotal = Convert.ToDouble(tb_SquareTotal.Text.Trim()); }
            catch { }
            try { o.SquareLive = Convert.ToDouble(tb_SquareLive.Text.Trim()); }
            catch { }
            try { o.SquareKit = Convert.ToDouble(tb_SquareKit.Text.Trim()); }
            catch { }
            try { o.AreaSquare = Convert.ToDouble(tb_AreaSquare.Text.Trim()); }
            catch { }

            try { o.Balcon = Convert.ToInt32(ddl_Balcons.SelectedValue); }
            catch { }
            try { o.Bathroom = Convert.ToInt32(ddl_Bathrooms.SelectedValue); }
            catch { }
            try { o.Bedroom = Convert.ToInt32(ddl_BedRoom.SelectedValue); }
            catch { }
            try { o.Kitchen = Convert.ToInt32(ddl_Kitchen.SelectedValue); }
            catch { }
            o.ToSea = tb_ToSea.Text.Trim() + "";
            o.Laundry = chb_Laundry.Checked;
            o.Storage = chb_Storage.Checked;
            o.Condition = chb_Condition.Checked;
            o.Farniture = chb_Farniture.Checked;
            o.Heating = chb_Heating.Checked;
            o.Parking = chb_Parking.Checked;
            o.SeaPanarama = chb_SeaPanarama.Checked;
            o.Garden = chb_Garden.Checked;
            o.Barbeku = chb_Barbeku.Checked;
            o.Pool = chb_Pool.Checked;
            o.Sallon = chb_Salon.Checked;
            o.Contacts = tb_Contacts.Text.Trim();

            o.Add();

            Response.Write(o.err);
            

        //}
        //catch(Exception ex) { Response.Write(ex.Message); }
    }
}
